import React from 'react';
import { connect } from 'dva';
import MessageList from '../../components/MessageList';
import SendMessage from '../../components/SendMessage';
import Checkmessage from '../../components/CheckMessage';

const MessageListPage = ({ dispatch, messageListState }) => {
  function handleDelete(id) {
    dispatch({
      type: 'products/delete',
      payload: id,
    });
  }
  function renderItem() {
    if (messageListState == 'sendmessage') {
      return <SendMessage />
    } else if (messageListState == 'checkmessage') {
      return <Checkmessage />
    } else {
      return <MessageList onDelete={handleDelete} />
    }
  }
  return (
    <div>
      {renderItem()}
    </div>
  );
};

export default connect(state => {
  const { messageListState } = state.message;
  return {
    messageListState
  }
})(MessageListPage);
